///修改图片路径
exports.changePicUrl = function(content,baseurl){
    var imgReg = /<img.*?(?:>|\/>)/gi;
    var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
    arr = content.match(imgReg);
	if(arr){
		for (var i = 0; i < arr.length; i++) {
		  var src = arr[i].match(srcReg);
		  var newsrc = baseurl+src[1];

		 var content = content.replace(src[1],newsrc);
		}
	}
    
    return content;
}
////分页
exports.getPage = function(req,allnum,num,where=''){
   ///获取当前url
   var path = this.dealUrl(req);
   var url = path.pathname +'?';
   ///获取总共页数
   var pagenum = Math.ceil(allnum/num);
   if(pagenum == 1){
    return '';
   }
   var page = req.query.p?req.query.p:1 ///当前页
   ///获取分页参数
   if(where){
	for(var k in where){
	 var params = '';
	 if(!where[k]){
	 	continue;
	 }
   	 params += k+'='+where[k]; 
     url += params;
    }
   }
   ///拼接地址
   var str = '';
   if(page > 1){
     str += '<li class="paginate_button0511 previous0511 next0511" aria-controls="DataTables_Table_0" tabindex="0" id="DataTables_Table_0_previous0511"><a href="'+url+'&p='+(page-1)+'">上一页</a></li>'
   }
   for(var i=1;i<=pagenum;i++){
       if(i==page){
         str +='<li class="paginate_button0511 active0511" aria-controls="DataTables_Table_0" tabindex="0"><a href="'+url+'&p='+i+'">'+i+'</a></li>'
       }else{
          str += '<li class="paginate_button0511 " aria-controls="DataTables_Table_0" tabindex="0"><a href="'+url+'&p='+i+'">'+i+'</a></li>'
       }
       
   }
   if(page < pagenum){
     str += '<li class="paginate_button0511 next0511" aria-controls="DataTables_Table_0" tabindex="0" id="DataTables_Table_0_next0511"><a href="'+url+'&p='+(parseInt(page)+parseInt(1))+'">下一页</a></li>'
   }
   var css = this.Css();
   str = css+'<div class="dataTables_paginate0511 paging_simple_numbers0511" id="DataTables_Table_0_paginate0511"><ul class="pagination0511" style="margin-top:50px">'+str+'</ul></div>';
   return str;
}
exports.dealUrl = function(req){
	var url = req.url;
	var U = require('url');
    var p = U.parse(url);
    return {pathname:p.pathname};
}
exports.Css = function(){
  return '<style>div.dataTables_paginate0511{text-align:center;margin:0;}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}div{display:block}.pagination0511>li{display:inline}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}li{display:list-item;text-align:-webkit-match-parent}.pagination0511>li:first-child>a,.pagination0511>li:first-child>span{margin-left:0;border-top-left-radius:4px;border-bottom-left-radius:4px}.pagination0511>.pagination0511>a,.pagination0511>.pagination0511>a:focus,.pagination0511>.pagination0511>a:hover,.pagination0511>.pagination0511>span,.pagination0511>.pagination0511>span:focus,.pagination0511>.pagination0511>span:hover{color:#777;cursor:not-allowed;background-color:#fff;border-color:#ddd}.pagination0511>li>a,.pagination0511>li>span{background-color:#FFF;border:1px solid #DDD;color:inherit;float:left;line-height:1.42857;margin-left:-1px;padding:4px 10px;position:relative;text-decoration:none}.pagination0511>li>a,.pagination0511>li>span{position:relative;float:left;padding:6px 12px;margin-left:-1px;line-height:1.42857143;color:#337ab7;text-decoration:none;background-color:#fff;border:1px solid #ddd}a{cursor:pointer}a{color:#337ab7;text-decoration:none}a{background-color:transparent}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}div.dataTables_paginate0511 ul.pagination0511{margin:2px 0;white-space:nowrap}.pagination0511{display:inline-block;padding-left:0;margin:20px 0;border-radius:4px}ol,ul{margin-top:0;margin-bottom:10px}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.pagination0511>.active0511>a,.pagination0511>.active0511>a:focus,.pagination0511>.active0511>a:hover,.pagination0511>.active0511>span,.pagination0511>.active0511>span:focus,.pagination0511>.active0511>span:hover{background-color:#f4f4f4;border-color:#DDD;color:#337ab7;cursor:default;z-index:2}</style>';
}